//chainmine.txt - Part of a chain of mines. It just sits there and can be disarmed.
//  It goes off when a trigmine object sends it message 105. 
//Cell 0 - Difficulty of trap ... the total tool use needed to disarm.
//Cell 1 - The effect created.
//  0 - fiery boom (1-6 dam/level)
//  1 - magical boom (1-8 dam/level)
//  2 - spray acid (1-2 pts/level)
//  3 - spray poison (1-2 pts/level)
//  4 - spawn creature (damage is spawn #, not in game #)
//  5 - debuff shield/bless
//  6 - debuff slow
//Cell 2 - The damage of the trap. Should be roughly equal to the level of 
//  the character you want to kill with it. Defaults to 6.
//Cell 3 - which mine
//  If the mine spawns a creature, this is the town roster of the creature (not in game #).

beginobjectscript; 

variables;
short disarmed = 0;
short exploded = 0;
short near_char;
short r1;
short cur_tick;
short trap_level = 6;
short warn = 0;

body;

beginstate INIT_STATE;
	trap_level = 20;
	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE; // door closed, waiting
	if ((disarmed) || (exploded))
		end();

	
	if (party_dist_to_nav(0) > 6)
		end();
	if ((gf(69,6) >= get_memory_cell(3)) && (warn == 0)) {
		warn = 1;
		print_str_color("One of the mines starts to hiss.",3);
		create_text_bubble("Hiss!");
		cur_tick = get_current_tick();
		create_missile_spiral(158,6,2,2);
		end();		
		}

	if (gf(69,6) < get_memory_cell(3))
		end();
	if (cur_tick == get_current_tick())
		end();
		
		exploded = 1;
		if (get_memory_cell(1) == 0) { // fire boom
			r1 = get_ran(1,150,200);
			run_sparkles_on_object(ME,173,1,4);
	  		create_missile_spiral(154,20,8,2);
			damage_nearby(r1,8,2,0);
			}
		if (get_memory_cell(1) == 1) { // magic boom
			r1 = get_ran(1,200,250);
			run_sparkles_on_object(ME,162,1,4);
	  		create_missile_spiral(155,20,8,2);
			damage_nearby(r1,8,1,0);
			}
		if (get_memory_cell(1) == 2) { // acid boom
			r1 = get_ran(15,1,2);
			run_sparkles_on_object(ME,12,9,1);
			spray_missiles(52,8,8);
			status_nearby(r1,8,6,0);
			play_sound(165); 
			}
		if (get_memory_cell(1) == 3) { // zap boom
			r1 = get_ran(8,1,2);
			run_sparkles_on_object(ME,13,9,1);
			spray_missiles(52,8,8);
			status_nearby(r1,8,2,0);
			play_sound(165); 
			}
		if (get_memory_cell(1) == 4) { // spawn creature
			spawn_creature(get_memory_cell(2));
			run_sparkles_on_object(ME,177,1,4);
				set_boss_level(8 + get_memory_cell(2),1);
				set_char_status(8 + get_memory_cell(2),0,8);
				set_char_status(8 + get_memory_cell(2),8,8);
			place_particle_num(get_memory_cell(2) + 8,10,7,10);
			}

		if (get_memory_cell(1) == 5) { // static
			r1 = get_ran(12,1,2);
			run_sparkles_on_object(ME,5,9,1);
			spray_missiles(42,8,8);
			status_nearby(-1 * r1,8,1,0);
			status_nearby(-1 * r1,8,0,0);
			status_nearby(-1 * r1,8,8,0);

			status_nearby(-30,8,9,0);
			status_nearby(-30,8,11,0);
			status_nearby(-30,8,12,0);
			status_nearby(-30,8,13,0);
			status_nearby(-30,8,14,0);
			status_nearby(-30,8,15,0);
			status_nearby(-30,8,16,0);
			status_nearby(-30,8,18,0);
			status_nearby(-30,8,19,0);

			play_sound(240); 
			}
		

break;

beginstate USE_STATE;
	if (exploded) {
		print_str("Disarm Mine: It's already gone off.");
		}
	else if (disarmed) {
		print_str("Disarm Mine: You already did.");
		}
	else if (get_stat(21) >= 8 + get_memory_cell(3)) {
		print_str("Disarm Mine: You manage to disable the trap!");
		pc_heard_sound(195);
		create_text_bubble("Click.");
		disarmed = 1;
		kill_object(ME,0);
		award_party_xp(BASE_TRAP_XP,trap_lev_to_xp_lev(4 + get_memory_cell(3)));
		run_sparkles_on_object(ME,1,1,0);
		}
		else {
			create_text_bubble("Ssssss!");
			print_big_str("Disarm Mine: Your Mechanics skill isn't high enough. (Difficulty: ",8 + get_memory_cell(3),").");
			}
break;